// pages/housetype/housetype/index.js
const app = getApp()
const utils = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    capBarMoveFlag:false,
    buildTypeName:"楼盘户型",
    boundButtonRect:{},
    bannerUrl:"https://testimg.quanyou.com.cn/group1/M01/01/3A/rB8MkmB1VTWAYEWgAAGQaz2yhq0821.jpg",
    buildTypeList:{},
    buildTypeLists:[
      {
        id:1,
        name:"滨江和成",
        text:'减肥哦啊接覅',
        appNewSeriesCoverImageUrl:"https://testimg.quanyou.com.cn/group1/M01/01/3A/rB8MkmB1VTWAYEWgAAGQaz2yhq0821.jpg"
      },{
        id:2,
        name:"滨江和成",
        text:'减肥哦啊接覅',
        appNewSeriesCoverImageUrl:"https://testimg.quanyou.com.cn/group1/M01/01/3A/rB8MkmB1VTWAYEWgAAGQaz2yhq0821.jpg"
      },{
        id:3,
        name:"滨江和成",
        text:'减肥哦啊金佛奥尔加of奥费劲儿OA接覅',
        appNewSeriesCoverImageUrl:"https://testimg.quanyou.com.cn/group1/M01/01/3A/rB8MkmB1VTWAYEWgAAGQaz2yhq0821.jpg"
      },{
        id:4,
        name:"滨江和成",
        text:'减肥哦啊金佛奥尔加of奥费劲儿OA接覅',
        appNewSeriesCoverImageUrl:"https://testimg.quanyou.com.cn/group1/M01/01/3A/rB8MkmB1VTWAYEWgAAGQaz2yhq0821.jpg"
      },{
        id:5,
        name:"滨江和成",
        text:'减肥哦接覅',
        appNewSeriesCoverImageUrl:"https://testimg.quanyou.com.cn/group1/M01/01/3A/rB8MkmB1VTWAYEWgAAGQaz2yhq0821.jpg"
      },{
        id:6,
        name:"滨江和成",
        text:'减肥哦啊金佛奥接覅',
        appNewSeriesCoverImageUrl:"https://testimg.quanyou.com.cn/group1/M01/01/3A/rB8MkmB1VTWAYEWgAAGQaz2yhq0821.jpg"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.handleGetBuildDetails(options.id)
    // this.getBoundButtonRect()
  },
  //点击户型进入方案列表界面
  goBuildDetail(e){
    const houseId=e.currentTarget.dataset.list.id
    const data={
      url:e.currentTarget.dataset.list.houseTypeImage,
      name:e.currentTarget.dataset.list.houseTypeName,
      house:e.currentTarget.dataset.list.houseModel,
      area:e.currentTarget.dataset.list.area,
    }
    wx.navigateTo({
      url: '/pages/housetype/buildcase/index?id='+houseId,
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('casepage', { data })
      }
    })
  },
  //获取楼盘详情信息
  handleGetBuildDetails(id){
    utils.$http(app.globalData.api.getBuildNameDetail, 
      { id}, 'get', true, 'JSON').then(res=>{
      if(res.success===1){
        res.data.deliveryTime=res.data.deliveryTime.slice(0,10)
        this.setData({
          buildTypeList:res.data
        })
        console.log(this.data.buildTypeList)
      }
    })
  },
  getBoundButtonRect:function(){
    let data = wx.getMenuButtonBoundingClientRect()
    const screenWidth =  app.globalData.screenWidth 
    let left = screenWidth - data.right
    let top = data.top
    let height = data.height
    let width = data.width
    this.setData(
      {
         boundButtonRect: {
           left,
           height,
           top,
           width
         }
      }
    )
  },
  goBack(){
    wx.navigateBack()
  },
  onPageScroll(e){
    const isSatisfy = e.scrollTop  >= 100  // 高度大于100的时候 显示白底标签栏
    if(this.data.capBarMoveFlag == isSatisfy) { 
      return false;
    } else {
      this.setData({
        capBarMoveFlag: isSatisfy
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})